import Vue from 'vue'
import App from './App.vue'
import Vuex from 'vuex'
import {ADD,SUB} from "./mutations-types"


Vue.use(Vuex)
let store= new Vuex.Store({
  state:{
    counter:666
  },

  //异步存放
  actions:{
    asyncAdd:function(store,step){
      setTimeout(function(){
        store.commit(ADD,step)
      },2000)
    }
  },
  //同步存放
  mutations:{
    [ADD]:function(state,step){
      console.log(step);
      state.counter+=step
    },
    [SUB]:function(state,payload){
      console.log(payload);
      state.counter+=payload.payload.step
    },
  },
  getters:{
    isOdd:function(state){
      return state.counter%2===0?"偶数":"奇数"
    }
  }
})
Vue.config.productionTip = false
new Vue({
  store,
  render: h => h(App),
}).$mount('#app')
